package com.github.od.rest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.github.od.bean.UserInfo;
import com.github.od.service.UserService;
import com.github.od.util.JWTUtil;
import com.github.od.vo.ObjectRestResponse;

/**
* JWT控制器
* 
* @author xieweikun
* @version 2017年11月16日 下午4:01:39
*/
@RestController
@RequestMapping("jwt")
public class JWTRest {
	@Autowired
	private JWTUtil jwtUtil;
	@Autowired
	private UserService userService;
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/token",method=RequestMethod.POST)
	public ObjectRestResponse<String> authorize(String username,String password) throws Exception {
		UserInfo info = userService.login(username, password);
		return new ObjectRestResponse<String>().data(jwtUtil.generateToken(info)); // 返回一个基准对象
	} 
}
